package cn.linjianhui.thread.sync;

public class BadLockOnInteger implements Runnable {

    static BadLockOnInteger instance = new BadLockOnInteger();
    static Integer i = 0;

    @Override
    public void run() {
        for(int k = 0; k < 10000; k++) {
            synchronized (i) {
                i++;
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new BadLockOnInteger());
        Thread t2 = new Thread(new BadLockOnInteger());
        t1.start(); t2.start();
        t1.join(); t2.join();
        System.out.println(i);
    }
}
